/**
 * @format
 * @Author: TC
 * @Date: 2023-07-26 21:31:01
 * @Last Modified by: TC
 * @Last Modified time: 2025-06-19 22:28:02
 */

import { AudioManager } from "./Manager/AudioManager";
import { ConfigManager } from "./Manager/ConfigManager";
import { EngineManager } from "./Manager/EngineManager";
import { EntityManager } from "./Manager/EntityManager";
import { EventManager } from "./Manager/EventManager";
import { InputCmdManager } from "./Manager/InputCmdManager";
import { KtxManager } from "./Manager/KtxManager";
import { NavMeshManager } from "./Manager/NavMeshManager";
import { PoolManager } from "./Manager/PoolManager";
import { PostEffectManager } from "./Manager/PostEffectManager";
import { ResManager } from "./Manager/ResManager";
import { SceneManager } from "./Manager/SceneManager";
import { SdkManger } from "./Manager/SdkManger";
import { ShaderManager } from "./Manager/ShaderManager";
import { StorageManager } from "./Manager/StorageManager";
import { TickManager } from "./Manager/TickManager";
import { TimerManager } from "./Manager/TimerManager";
import { UIManager } from "./Manager/UIManager";
import { nsBin } from "./Util/BinUtility";
import { nsComponent } from "./Util/ComponentUtil";
import { nsExtend } from "./Util/ExtendUtil";
import { nsJsZip } from "./Util/JsZipUtlity";
import { nsLog } from "./Util/LogUtil";
import { nsMath } from "./Util/MathUtil";
import { nsTaskUtil } from "./Util/TaskUtil";

/**
 * 程序入口
 */
class App {
    /**
     * 启动框架
     * @param cb 启动完成回调
     */
    public static start(cb?: Function): void {
        //初始化本地数据
        this.storageMgr.init();
        //启动定时器
        this.timerMgr.start();
        //初始化UI列表
        this.uiMgr.init();
        //注册全局事件监听
        this.eventMgr.init();
        //初始化引擎
        this.engineMgr.init();
        //初始化压缩纹理
        this.ktxMgr.init().then(() => {
            app.log.log("框架启动完成");
            cb && cb();
        });
    }

    //#region 管理类
    //资源管理
    private static _resMgr: ResManager = null;
    public static get resMgr(): ResManager {
        return this._resMgr || (this._resMgr = new ResManager());
    }
    //场景管理
    private static _sceneMgr: SceneManager = null;
    public static get sceneMgr(): SceneManager {
        return this._sceneMgr || (this._sceneMgr = new SceneManager());
    }

    //UI管理
    private static _uiMgr: UIManager = null;
    public static get uiMgr(): UIManager {
        return this._uiMgr || (this._uiMgr = new UIManager());
    }

    //事件管理
    private static _eventMgr: EventManager = null;
    public static get eventMgr(): EventManager {
        return this._eventMgr || (this._eventMgr = new EventManager());
    }

    //定时器管理
    private static _timerMgr: TimerManager = null;
    public static get timerMgr(): TimerManager {
        return this._timerMgr || (this._timerMgr = new TimerManager());
    }
    //配置管理
    private static _cfgMgr: ConfigManager = null;
    public static get cfgMgr(): ConfigManager {
        return this._cfgMgr || (this._cfgMgr = new ConfigManager());
    }

    //对象池管理
    private static _poolMgr: PoolManager = null;
    public static get poolMgr(): PoolManager {
        return this._poolMgr || (this._poolMgr = new PoolManager());
    }
    //本地数据管理
    private static _storageMgr: StorageManager = null;
    public static get storageMgr(): StorageManager {
        return this._storageMgr || (this._storageMgr = new StorageManager());
    }

    //音频管理
    private static _audioMgr: AudioManager = null;
    public static get audioMgr(): AudioManager {
        return this._audioMgr || (this._audioMgr = new AudioManager());
    }
    //SDK管理
    private static _sdkMgr: SdkManger = null;
    public static get sdkMgr(): SdkManger {
        return this._sdkMgr || (this._sdkMgr = new SdkManger());
    }
    //输入管理
    private static _inputMgr: InputCmdManager = null;
    public static get inputMgr(): InputCmdManager {
        return this._inputMgr || (this._inputMgr = new InputCmdManager());
    }
    //ktx管理
    private static _ktxMgr: KtxManager = null;
    public static get ktxMgr(): KtxManager {
        return this._ktxMgr || (this._ktxMgr = new KtxManager());
    }
    //引擎管理
    private static _engineMgr: EngineManager = null;
    public static get engineMgr(): EngineManager {
        return this._engineMgr || (this._engineMgr = new EngineManager());
    }
    //tick管理
    private static _tickMgr: TickManager = null;
    public static get tickMgr(): TickManager {
        return this._tickMgr || (this._tickMgr = new TickManager());
    }
    //实体管理
    private static _entityMgr: EntityManager = null;
    public static get entityMgr(): EntityManager {
        return this._entityMgr || (this._entityMgr = new EntityManager());
    }
    //#endregion 管理类

    //#region 辅助类
    public static log = nsLog;
    public static task = nsTaskUtil;
    public static bin = nsBin;
    public static jsZip = nsJsZip;
    public static math = nsMath;
    public static component = nsComponent;
    //#endregion 辅助类

    /*******************manager******************* */
    public postEffectMgr: PostEffectManager = PostEffectManager.instance;
    public shaderMgr: ShaderManager = ShaderManager.instance;
    public navMeshMgr: NavMeshManager = NavMeshManager.instance;
    /*******************manager******************* */
}

export const app = App;
